package com.deyuanyun.pic.ctrl.validatefun;

import com.deyuanyun.pic.common.validator.vinterface.ValidateInterface;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.Field;

/**
 * 模块描述
 *
 * @author scalpel.王敏
 * @version [v1.0] 创建时间（2016/11/3）
 * @see // 引用的类
 * Method List:
 * 1.----------------
 * 2.----------------
 * History:
 */
public class ClickValid implements ValidateInterface {
    @Override
    public <T, E, C> boolean apply(T t, E e, C c) throws NoSuchFieldException {
        Field f = (Field) e;
        String val = (String) t;
        if (val != null && !"".equals(val)) {
            String vals[] = val.split(":");
            if (vals.length == 1) {
                return false;
            }
            try {
                int h = Integer.parseInt(vals[0]);
                int m = Integer.parseInt(vals[1]);
                if (h < 0 || h > 12 || m < 0 || m > 60) {
                    return false;
                }
                if(h == 12 && m >0)
                {
                    return false;
                }
                val = (h<10?"0"+h:h)+":"+(m<10?"0"+m:m);
                BeanUtils.setProperty(c,f.getName(),val);

            } catch (Exception x) {
                return false;
            }


            return true;
        }
        return true;
    }
        @Override
        public String getName () {
            return null;
        }
    }